package com.wonderful.mall.search.web;

import com.wonderful.mall.search.service.MallSearchService;
import com.wonderful.mall.search.vo.SearchParam;
import com.wonderful.mall.search.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@Controller
@Slf4j
public class IndexController {


    @Resource
    private MallSearchService mallSearchService;

    @GetMapping({"/", "/index.html", "/list.html"})
    public String listPage(SearchParam param, Model model, HttpServletRequest request) {
        param.set_queryString(request.getQueryString());
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result", result);
        return "list";
    }
}
